package com.ay.smartpark.sdk.controller;

import com.ay.smartpark.sdk.common.base.ResponseBean;
import com.qycloud.SDK.server.client.DecodeAndEncodeClient;
import com.qycloud.SDK.server.client.UserClient;
import com.qycloud.SDK.server.dto.UserEntityDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    private DecodeAndEncodeClient decodeAndEncodeClient;

    @Resource
    private UserClient userClient;

    @RequestMapping("/registerUser")
    public ResponseBean registerUser() {
        try {
            UserEntityDTO userEntityDTO = new UserEntityDTO();
            userEntityDTO.setUserId("user20190101");
            userEntityDTO.setPassword(decodeAndEncodeClient.encode3DES("user20190101"));
            userEntityDTO.setRealName("用户20190101");
            userEntityDTO.setPinyin("user20190101");
            userEntityDTO.setAvatar("");
            userEntityDTO.setSex(1);
            userEntityDTO.setEmail("user20190101@qq.com");
            userEntityDTO.setCreateTime(new Date());
            userEntityDTO.setLastLoginTime(new Date());
            userEntityDTO.setLastLoginEnterprise("ceshi20190101");
            userEntityDTO.setLastLoginEnterpriseMobile("ceshi20190101");
            userEntityDTO.setIsAdWelcome(1);
            userEntityDTO.setBirthday(new Date());
            userEntityDTO.setLoginUserId("user20190101");
            userEntityDTO.setLastModified("2018-12-10");
            userEntityDTO.setVerifyTwo(0);
            userEntityDTO.setResetPwd(0);
            userEntityDTO.setTheme("blue");
            userEntityDTO.setRegType(1);
            userEntityDTO.setBirthType(0);
            userEntityDTO.setPwGrade(1);
            userEntityDTO.setLeadNewUser("");
            userEntityDTO.setLeadHeader("");
            /**
             * entId：
             *  中化： zhonghuawuliugangxin
             *  海盐： kaifaquhuagongyuanfe
             */
            Integer result = userClient.registryUser("zhonghuawuliugangxin", userEntityDTO, 1, 1);
            return ResponseBean.success(result);
        } catch (Exception e) {
            logger.error("registerUser error:", e);
            return ResponseBean.fail("");
        }

    }
}
